package com.ssy.lingxi.member.merchant.model.constant;

import com.ssy.lingxi.common.language.LanguageHolder;
import com.ssy.lingxi.member.merchant.model.vo.basic.response.DropdownItem;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * （商户、渠道）会员关系外部状态枚举
 * @author 万宁
 * @version 2.0.0
 * @date 2021-05-29
 */
public enum MemberOuterStatusEnum {
    /**
     * 待提交平台审核 - 1
     */
    TO_PLATFORM_VERIFY(1, "待提交审核"),

    /**
     * 待平台审核（平台审核未完成）- 2
     */
    PLATFORM_VERIFYING(2, "待平台审核"),

    /**
     * 平台审核通过 - 3
     */
    PLATFORM_VERIFY_PASSED(3, "平台审核通过"),

    /**
     * 平台审核不通过 - 4
     */
    PLATFORM_VERIFY_NOT_PASSED(4, "平台审核不通过"),

    /**
     * 待审核会员入库 - 5
     */
    DEPOSITING(5, "待审核会员入库"),

    /**
     * 入库审核通过 - 6
     */
    DEPOSITORY_PASSED(6, "入库审核通过"),

    /**
     * 入库审核不通过 - 7
     */
    DEPOSITORY_NOT_PASSED(7, "入库审核不通过"),

    /**
     * 待审核会员变更 - 8
     */
    MODIFYING(8, "待审核会员变更"),

    /**
     * 会员变更审核通过 - 9
     */
    MODIFY_PASSED(9, "会员变更审核通过"),

    /**
     * 会员变更审核不通过 - 10
     */
    MODIFY_NOT_PASSED(10, "会员变更审核不通过"),

    /**
     * 未知（初始状态） - 99
     */
    Unknown(99, "未知");

    MemberOuterStatusEnum(Integer code, String msg) {
        this.code = code;
    }

    private final Integer code;

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return LanguageHolder.getName(this.getClass(), this.getCode());
    }

    public static String getCodeMsg(Integer code) {
        return LanguageHolder.getName(MemberOuterStatusEnum.class, code);
    }

    public static List<DropdownItem> toDropdownList() {
        return Arrays.stream(MemberOuterStatusEnum.values()).filter(e -> !e.getCode().equals(Unknown.getCode())).sorted(Comparator.comparingInt(MemberOuterStatusEnum::getCode)).map(e -> new DropdownItem(e.getCode(), e.getMsg())).collect(Collectors.toList());
    }

    public static MemberOuterStatusEnum parseCode(Integer code) {
        return Arrays.stream(MemberOuterStatusEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(Unknown);
    }

    /**
     * 会员已入库外部状态
     * @return 状态集合
     */
    public static List<MemberOuterStatusEnum> depositOuterStatus(){
        return Arrays.asList(MemberOuterStatusEnum.DEPOSITORY_PASSED,
                MemberOuterStatusEnum.MODIFYING,
                MemberOuterStatusEnum.MODIFY_PASSED,
                MemberOuterStatusEnum.MODIFY_NOT_PASSED);
    }
}
